const fs = require('fs');

var data = '这是我要写入的内容！\n';

var wrs = fs.createWriteStream('data.txt',{flags: 'a+'});

wrs.write(data);

wrs.end();

wrs.on('finish', function(){
    console.log('写入完成！');
});

wrs.on('error', function(err){
    console.log(err);
});